var clickUtils = require("../../utils/clickUtils");
var textUtils = require("../../utils/textUtils");
var ocrUtils = require("../../utils/ocrUtils");
var randomUtils = require("../../utils/randomUtils");
var adXiGua = require("../../ads/xiGua/index");
var Action = require("../../base/Action");
var aWatchAd = new Action("看广告", {
  interval: 15,
  maxRunSCount: 10,
});
aWatchAd.startWatchAd = function () {
  sleep(randomUtils.getRandom(2.5, 5, 1000));
  var maxAdCount = randomUtils.getRandom(2, 5);
  adXiGua.startWatchAd(maxAdCount);
  sleep(randomUtils.getRandom(2.5, 5, 1000));
  this.afterWatchAd();
};
aWatchAd.afterWatchAd = function () {
  var content = "开心收下";
  var TextUI = textUtils.existsTextStartsWith(content);
  if (TextUI) {
    clickUtils.clickTextUI(TextUI);
    sleep(randomUtils.getRandom(1.5, 3, 1000));
    this.runSCount++;
    return;
  }
  var TextOCR = ocrUtils.captureExistsText(content);
  if (TextOCR) {
    clickUtils.clickTextOCR(TextOCR);
    sleep(randomUtils.getRandom(1.5, 3, 1000));
    this.runSCount++;
    return;
  }
};
aWatchAd.exec = function () {
  var content = "看广告赚金币";
  var TextUI = textUtils.existsTextStartsWith(content);
  if (TextUI) {
    clickUtils.clickTextUI(TextUI);
    this.startWatchAd();
    return;
  }
  var TextOCR = ocrUtils.captureExistsText(content);
  if (TextOCR) {
    clickUtils.clickTextOCR(TextOCR);
    this.startWatchAd();
    return;
  }
};

module.exports = aWatchAd;
